
export function formatDateTime(date) {
  var y = date.getFullYear();
  var m = date.getMonth() + 1;//注意这个“+1”
  m = m < 10 ? ('0' + m) : m;
  var d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  var h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  var minute = date.getMinutes();
  minute = minute < 10 ? ('0' + minute) : minute;
  var second = date.getSeconds();
  second = second < 10 ? ('0' + second) : second;
  return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}



export function timeFilter(n) {
  let date = new Date();
  let dt = new Date(n);
  let str = '';
  let minute = (date.getTime() - dt.getTime()) / 1000 / 60;

  var y = dt.getFullYear();
  var m = dt.getMonth() + 1;//注意这个“+1”
  m = m < 10 ? ('0' + m) : m;
  var d = dt.getDate();
  d = d < 10 ? ('0' + d) : d;
  var h = dt.getHours();
  h = h < 10 ? ('0' + h) : h;
  var mm = dt.getMinutes();
  mm = mm < 10 ? ('0' + mm) : mm;

  var todayY = date.getFullYear()
  var todayM = date.getMonth() + 1
  todayM = todayM < 10 ? ('0' + todayM) : todayM;
  var todayD = date.getDate()
  todayD = todayD < 10 ? ('0' + todayD) : todayD;

  var isToday = ('' + y + m + d) == ('' + todayY + todayM + todayD)

  if (parseInt(minute) === 0) {
    return '刚刚';
  } else if (10 > parseInt(minute)) {
    return parseInt(minute) + '分钟前';
  } else if (isToday) {
    return h + ':' + mm
  } else {
    // return parseInt(minute / 60 / 24) + '天' + (parseInt(minute / 60) - parseInt(minute / 60 / 24) * 24) + '小时' + parseInt(minute - parseInt(minute / 60) * 60) + '分钟前'
    return y + '年' + m + '月' + d + '日' + ' ' + h + ':' + mm
  }
}



